﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.Database;
using Project.Database.Repository;
using Project.Interfaces;
using Project.Implementations.ClickHandler;
using Project.Implementations;

namespace Project.Controllers
{
    public class ClickController : Controller
    {
        private DatabaseRepository entities = new DatabaseRepository();
        private IClickHandler ClickHandler = new DefaultClickHandler();

        public HttpStatusCodeResult Index()
        {
            return HttpNotFound();
        }
        //
        public ActionResult AdClick(int u, int a, int b)
        {
            string serverName = Server.MachineName;
            string clientIP = Utils.GetIP();
            DateTime dateStamp = HttpContext.Timestamp;

            ClickHandler.ProcessClick(u, a, b, clientIP, dateStamp);
            return Redirect("http://"+entities.GetAdvert(a).TargetURL);
        }

        // POST: /Click/
        [HttpPost]
        public EmptyResult AdClickK(int userID, int advertID, int blogID)
        {
            string serverName = Server.MachineName;
            string clientIP = Utils.GetIP();
            DateTime dateStamp = HttpContext.Timestamp;

            ClickHandler.ProcessClick(userID, advertID, blogID, clientIP, dateStamp);

            return new EmptyResult(); 
        }

    }
} 
